package com.lk.util;

import com.lk.enums.CodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

/**
 * @author : lk
 * @date 2021/11/20 15:58
 **/
@Data
@AllArgsConstructor
public class Result<T> implements Serializable {

    private Integer code;

    private String message;

    private T data;

    private Result() {
    }

    public static <T> Result<T> success() {
        return of(CodeEnum.OK.getCode(), CodeEnum.OK.getMessage(), null);
    }

    public static <T> Result<T> success(T data) {
        return of(CodeEnum.OK.getCode(), CodeEnum.OK.getMessage(), data);
    }

    public static <T> Result<T> fail(Integer code, String message) {
        return of(code, message, null);
    }

    public static <T> Result<T> fail() {
        return of(CodeEnum.FAIL.getCode(), CodeEnum.FAIL.getMessage(), null);
    }

    public static <T> Result<T> of(Integer code, String message, T data) {
        return new Result<>(code, message, data);
    }
}
